#include <base/array.h>

#include <stdio.h>

struct sData {
  const char *name;
  unsigned age;
  bool man;
  static sData* instance(const char *_name, unsigned _age, bool _man) {
    return new sData(_name, _age, _man);
  }
  void release() { delete this; }
  protected:
    sData(const char *_name, unsigned _age, bool _man)
      : name(_name), age(_age), man(_man) {}
};
typedef base::array<sData*> Array;

void release_sdata(Array *array) {
  for (unsigned i = 0; i < array->size(); ++i) {
    auto d = array->at(i);
    d->release();
  }
}
void dump(Array *array) {
  printf("--------");
  printf("Array Size: %d\n", array->size());
  printf("Array Data: \n");
  for (unsigned i = 0; i < array->size(); ++i) {
    auto d = array->at(i);
    printf("  %d: %s, %d, %d\n", i
      , d->name, d->age, d->man);
  }
}

void test_() {}

int main(int argc, char **argv) {
  Array array;
  Array array2;

  dump(&array);

  array.add(sData::instance("dzlua", 18, true));
  dump(&array);

  array.swap(&array2);

  dump(&array);

  release_sdata(&array);
  release_sdata(&array2);
  
  return 0;
}